import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: { // 
    token: "",
    str: ''
  },
  mutations: { // 
    'UPDATE_TOKEN'(state, token) {
      state.str = token
      console.log(token, 'token')
      state.token = token
    }
  },
  actions: {
    updateToken({ commit }, token) {
      commit('UPDATE_TOKEN', token)
    }
  },
  getters: {

  },
  modules: {
  }
})

store.subscribe((mutation, state) => {
  console.log(state.token, '我在插件中')
  // 监听mutaion提交，做出响应的行为
  sessionStorage.setItem('token', state.token)
})


export default store;